
#include "Color.h"
#include "Math.h"

#include <algorithm>

using namespace Iride;

const Color Color::Black = Color( 0.0f, 0.0f, 0.0f);
const Color Color::White = Color( 1.0f, 1.0f, 1.0f);
const Color Color::Red = Color( 1.0f, 0.0f, 0.0f);
const Color Color::Green = Color( 0.0f, 1.0f, 0.0f);
const Color Color::Blue = Color( 0.0f, 0.0f, 1.0f);
const Color Color::Yellow = Color( 1.0f, 1.0f, 0.0f);
const Color Color::DarkRed = Color( (Byte) 139, 0.0f, 0.0f);
const Color Color::CornflowerBlue = Color( 1.0f, 1.0f, 0.0f);

Color::Color()
{
	r = 0.0f;
	g = 0.0f;
	b = 0.0f;
	a = 1.0f;
};

Color::Color(Real red, Real green, Real blue, Real alpha)
{
	r = red;
	g = green;
	b = blue;
	a = alpha;
};

Color::Color(Real red, Real green, Real blue)
{
	r = red;
	g = green;
	b = blue;
	a = 1.0f;
};


void Color::Swap(Color &rOther)
{
	std::swap(r, rOther.r);
	std::swap(g, rOther.g);
	std::swap(b, rOther.b);
	std::swap(a, rOther.a);
}

Color Color::operator+ (const Color& col) const
{
	Color result;
	result.r = r + col.r;
	result.g = g + col.g;
	result.b = b + col.b;
	result.a = a + col.a;

	return result;
}

Color Color::operator- (const Color& col) const
{
	Color result;
	result.r = r - col.r;
	result.g = g - col.g;
	result.b = b - col.b;
	result.a = a - col.a;

	return result;
}

Color Color::operator* (const float& coeff) const
{
	Color result;
	result.r = coeff * float(r);
	result.g = coeff * float(g);
	result.b = coeff * float(b);
	result.a = coeff * float(a);

	return result;
}

Color Color::operator/ (const float& coeff) const
{
	Color result;
	result.r = r / float(coeff);
	result.g = g / float(coeff);
	result.b = b / float(coeff);
	result.a = a / float(coeff);

	return result;
}

Color& Color::operator+= (const Color& col)
{
  *this = *this + col;
  return *this;
}

Color& Color::operator-= (const Color& col)
{
  *this = *this - col;
  return *this;
}

void Color::Saturate()
{
  r = Math::Clamp(r,0.0f,1.0f);
  g = Math::Clamp(g,0.0f,1.0f);
  b = Math::Clamp(b,0.0f,1.0f);
  a = Math::Clamp(a,0.0f,1.0f);
}

